home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / c / parse.lha / ex.c < prev    next >
C/C++ Source or Header  |  1992-08-11  |  2KB  |  63 lines

  1. /*** exemple d'utilisation (début seulement) %%% use sample (beginning) ***/
  2.  
  3. #include <stdio.h>
  4. #include "parse.h"
  5.  
  6. #define OPTIONS "f;h i "
  7.  
  8. #ifndef ENGLISH
  9. #  define UNSET   "pas mise"
  10. #else
  11. #  define UNSET   "unset"
  12. #endif
  13.  
  14. void main (int narg, char * parg [])
  15. {
  16.    struct rapport rapport;
  17.    char nopt;
  18.  
  19.    if ((nopt = parse(OPTIONS, narg, parg, &rapport)) < 0) {
  20.       if (rapport.erreur != OPT_LACK_OF_MEMORY) {
  21.          fprintf(stderr, ParseErrMess, rapport.lettre);
  22.          if (rapport.erreur == OPT_UNKNOWN_OPTION)
  23.             fprintf(stderr, "\nUSAGE : parse [-f <file>] [-h] [-i] <arg>");
  24.       } else
  25.          fprintf(stderr, ParseErrMess);
  26.       fputc('\n', stderr);
  27.       exit(10);
  28.    }
  29.    /* maintanant il nous faut utiliser les argv et arc donnes dans rapport
  30.       now we have to use the argv and argc provided in rapport             */
  31.    if (rapport.narg  != 1) {
  32.       fprintf(stderr, "USAGE : parse [-f <fichier>] [-h] [-i] <argument>\n");
  33. #        ifndef ENGLISH
  34.       if (narg)
  35.          fprintf(stderr, "Il y a %d arguments au lieu d'un seul !\n",  rapport.narg);
  36.       else
  37.          fprintf(stderr, "Il faut un argument !\n");
  38. #        else  /* ENGLISH  */
  39.       if (narg)
  40.          fprintf(stderr, "There are %d arguments instead of a single one!\n",  rapport.narg);
  41.       else
  42.          fprintf(stderr, "There must be an argument!\n");
  43. #        endif /* ENGLISH  */
  44.          /* faire le ménage avant de partir.  ## let's clean and quit.  */
  45.          parse_cleanup();
  46.          exit(10);
  47.    }
  48.    /* pas d'erreur de syntaxe détectée
  49.       no syntax error was encountered  */
  50.    printf("%d options\noption f %s%s\noption h %s\noption i %s\nargument = %s\n",
  51.           nopt,
  52.           (rapport.options[0]) ? "set to " : UNSET,
  53.           (rapport.options[0]) ? rapport.arguments[0] : "",
  54.           (rapport.options[1]) ? "set" : UNSET,
  55.           (rapport.options[2]) ? "set" : UNSET,
  56.           rapport.parg[0]
  57.           );
  58.    /* faire le ménage avant de partir.  ## let's clean and quit.  */
  59.    parse_cleanup();
  60.    exit(0);
  61. }
  62.  
  63.